package com.huibao.hulibao.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.huibao.hulibao.R;
import com.huibao.hulibao.entity.KeHuEntity;

import java.util.ArrayList;

/**
 * Created by lizhaoyong on 2018/5/8.
 */
public class KehuGvAdapter extends BaseAdapter {

    public ArrayList<KeHuEntity> al_datas;
    public Context context;
    public int kehu_selected_index;

    public KehuGvAdapter(Context context, ArrayList<KeHuEntity> al_datas, int kehu_selected_index) {
        this.context = context;
        this.al_datas = al_datas;
        this.kehu_selected_index = kehu_selected_index;
    }

    @Override
    public int getCount() {
        return al_datas.size();
    }

    @Override
    public Object getItem(int i) {
        return al_datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View v = View.inflate(context, R.layout.item_gv_kehu, null);
        TextView tv = (TextView) v.findViewById(R.id.tv_kehu_name);
        KeHuEntity khe = al_datas.get(i);
        tv.setText(khe.CustomerName + "(" + khe.CustomerRoom + ")");
        // tv.setText(al_datas.get(i));
        // 如果用户有选中就显示选中的样式
        if (kehu_selected_index != -1) {
            if (i == kehu_selected_index) {
                tv.setBackground(context.getResources().getDrawable(R.drawable.corner_view_kehu_selected_5radio));
                tv.setTextColor(context.getResources().getColor(R.color.white));
            } else {
                tv.setBackground(context.getResources().getDrawable(R.drawable.corner_view_kehu_no_selected_gray_5radio));
                tv.setTextColor(context.getResources().getColor(R.color.text_black));
            }
        }

        return v;
    }
}
